import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class _26_删除有序数组中的重复项 {
    @Test
    public void test(){
        int []nums = {0,0,1,1,1,2,2,3,3,4};
        System.out.println(removeDuplicates(nums));

    }

    /**
     * 双指针法：先将一个指针
     * @param nums
     * @return
     */
    public int removeDuplicates(int[] nums) {
        if (nums==null||nums.length==1) return nums.length;
        int left=0,right=1;
        while (right<nums.length){
            if (nums[left]==nums[right]){
                right++;
            }else {
                left++;
                nums[left]=nums[right];
                right++;
            }
        }
        return left+1;
    }
}
